<?php

class McCube_Template_Helper{

    protected static $_register = array(
        'Theme' => array(
              'class' => 'McCube_Theme'
            , 'type'  => 'dynamic'
            , 'method'=> 'singleton'
            , 'return'=> 'object'
        )
        , 'Html' => array(
              'class' => 'McCube_Html'
            , 'type'  =>'dynamic'
            , 'method'=> 'direct'
        )
    );

    protected static function _set($name, $value=''){
        if(self::$_register[$name]['type'] == 'dynamic'){
            if(self::$_register[$name]['method'] == 'singleton'){
                $class = self::$_register[$name]['class'];
                self::$_register[$name]['instance'] = $class::get($value);
            } else {
                self::$_register[$name]['instance'] = new self::$_register[$name]['class']();
            }
        }
    }

    public static function get($name, $value=''){
        if(!isset(self::$_register[$name]['instance']))
            self::_set($name, $value);

        if($value && self::$_register[$name]['return'] != 'object')
            return self::$_register[$name]['instance']->{'get'.ucfirst($value)}();

        return self::$_register[$name]['instance'];
    }
}